from keras.models import load_model
from keras.datasets import imdb
import numpy as np

load_model = load_model('D:\code\DeepBloom-master\model\keras_gru_model.h5')

# number_words表示仅仅保留10000个最常的出现的单词，用于限制features的最大长度（即：results中列数最多10000）
(train_data, train_labels), (test_data, test_labels) = imdb.load_data(num_words=10000)
# train_data:(1,25000)

def vectorize_sequences(sequences, dim=10000):
    # sequences[0]:list 218
    # 行数i：sequence；列数j：单词出现频率
    results = np.zeros((len(sequences), dim))
    for i, j in enumerate(sequences):
        results[i, j] = 1
    return results


x_train = vectorize_sequences(train_data)
# (25000,10000):由0/1组成的二维矩阵
x_test = vectorize_sequences(test_data)
# (25000,10000):由0/1组成的二维矩阵
# 分出部分测试数据
unknown = x_train[9:10]
unknown2 = x_test[:1]

sum = 0
arr = x_train[:9][0]
for i in range(len(arr)):
    sum = sum + arr[i]
print("sum:", sum, "\n")
predicted = load_model.predict(unknown)
print("predicted data:", predicted)